{extend name="layout:base" /}

{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="test-table-reload-btn">
                <div class="layui-inline">
                    <button id="btnAdd" class="layui-btn layui-btn-sm layuiadmin-btn-list" data-type="add">添加客户</button>
                </div>
                <div class="layui-inline">
                    <select name="project_id" id="project_id" lay-filter="project_id">
                        <option value="0">产品类型</option>
                        {volist name="projects" id="vo"}
                        <option value="{$vo.id}">{$vo.title}</option>
                        {/volist}
                    </select>
                </div>
                <div class="layui-inline">
<!--                    <input class="layui-input" name="keywords" id="keywords" autocomplete="off">-->
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="tbList" class="layui-table" lay-filter="tbList" ></table>

            <script type="text/html" id="op">
                <a class="layui-btn layui-btn-xs" lay-event="showlist" title="点击查看跟进记录"> 查看记录 </a>
            </script>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'util','form'], function () {

        var $ = layui.$,form = layui.form,layer = layui.layer,table = layui.table;
        table.render({
            elem: '#tbList',
            url: "{:url('getList')}?type=index",
            cellMinWidth: 80,
            cols: [[
                {field: 'id', fixed: 'left',width:60, title: 'id', sort: false},
                {field: 'project_name',fixed:'left',title:'产品',sort: true},
                {field: 'type',title:'签单类型',width:120,sort: true,
                    templet: function (d) {
                        if (d.type=='协助'){
                            return d.type+'&nbsp;&nbsp;<a class="layui-btn layui-btn-xs" lay-event="show" href="javaScript:(0);" title="点击查看资料">查看</a>'
                        }else{
                            return d.type
                        }
                    }
                },
                {field: 'state',title:'是否签单',sort: true,templet: function (d) {
                        if (d.state==1){return '是'}else{return ''}
                    }
                },
                {field: 'pay_type',title:'公私',sort: true},
                {field: 'pay_img',title:'工资',width:60,sort: true,templet: function (d) {
                        if (d.pay_img){
                            return '<a href='+d.pay_img+' target="_blank" title="点击查看大图" ><img  src='+d.pay_img+' width=50></a>'
                        }else {
                            return ''
                        }
                    }
                },
                {field: 'pay_real',title:'应发工资',sort: true},
                {field: 'money',title:'签单金额',sort: true},
                {field: 'created_time',title:'下单时间',sort: true},
                {fixed: 'right', title: '跟进记录', toolbar: '#op'}
            ]],
            page: true,
            limit:15,
        });

        // 监听工具条
        table.on('tool(tbList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'showlist') {
                var url = "{:url('showlist')}?id=" + data['id'];
                var index = layer.open({
                    type: 2,
                    title: '跟进记录',
                    area: ['90%', '90%'],
                    shade: 0,
                    content: url,
                    zIndex: layer.zIndex
                });
            }else if (obj.event === 'show') {
                var url = "{:url('show_taskinfo')}?id=" + data['id'];
                var index = layer.open({
                    type: 2,
                    title: '订单资料',
                    area: ['50%', '50%'],
                    shade: 0,
                    content: url,
                    zIndex: layer.zIndex
                });
            }
        });

        //操作
        var $ = layui.$, active = {
            reload: function(){
                var project_id=$('#project_id').val();
                var keywords=$('#keywords').val();

                //执行重载
                table.reload('tbList', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        project_id: project_id
                        ,keywords: keywords
                    }
                });

            }
        };

        $('.layui-card-header .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
{/block}